filename = "guest_book.txt"

active = True
while active:
    name = input("请输入你的名字（输入'q'退出）：")
    if name == 'q':
        active = False
    else:
        print(f"你好呀，{name}!")
        with open(filename, 'a') as file_object:
            file_object.write(name + '\n')

with open(filename) as file_object:
    for line in file_object:
        print(line.rstrip())